package net.jueb.protoServer.handler;

import java.util.concurrent.ConcurrentHashMap;
import net.jueb.protoServer.portService.PortService;
import net.jueb.protoServer.portService.PortService.PortType;
import io.netty.channel.socket.DatagramChannel;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;

/**
 * Udp服务端口初始化
 * 根据服务器提供的服务列表查询对应端口以及对应的Tcp类型服务并初始化
 * @author Administrator
 *
 */
public final class UdpServicePortInitializer extends ServicePortInitializer<DatagramChannel> {
	
	protected static final InternalLogger log = InternalLoggerFactory.getInstance(UdpServicePortInitializer.class);
	/**
	 * 所有线程公用
	 */
	protected final ConcurrentHashMap<Integer,PortService<?>> portServices;
	
	
	
	public UdpServicePortInitializer(ConcurrentHashMap<Integer, PortService<?>> portServices) {
		this.portServices=portServices;
	}
	@Override
	public final PortType getPortType() {
		return PortType.UDP;
	}
	@Override
	protected void initChannel(DatagramChannel channel) throws Exception {
//		int port=channel.localAddress().getPort();
//		PortService ps=portServices.get(port);
		log.debug("UdpChannel:"+channel);
//		if(ps!=null && port==ps.getPort() && getPortType()==ps.getPortType())
//		{//如果存在对应端口服务，且端口协议正确
//			//初始化端口
//			channel.pipeline().addLast(ps.getMessageDecoderHandler());
//			channel.pipeline().addLast(ps.getMessageEncoderHandler());
//			channel.pipeline().addLast(ps.getMessageDispatcher());//加入消息分发handler
//			log.debug("UDP端口:"+port+"初始化");
//		}
//		log.error("端口"+port+"未匹配到端口服务");
//		return ;
	}
}
